import {
	defineStore
} from 'pinia';
import {
	toGetSchoolList,
	toGetSchoolById

} from "@/utils/request/school.js"
export const useSchoolStore = defineStore('school', {
	state: () => {
		return {
			status: {
				code: "",
				msg: ""
			},
			schoolList: [],
			school: {}

		};
	},
	// 也可以这样定义
	// state: () => ({ count: 0 })
	actions: {
		async getSchoolById(id) {
			try {
				this.school = []
				const res = await toGetSchoolById(id);
				this.status.code = res.code;
				this.status.msg = res.msg
				if (res.code == "200") {
					if (res.data.imgSrc != null && res.data.imgSrc != "") {
						res.data.imgSrc = res.data.imgSrc.split(";")
					}
					this.school = res.data
				}
			} catch (err) {
				this.status.code = "405",
					this.status.msg = "网络不好，请稍后重试"
			}
		},
		async getSchoolList() {
			try {
				this.schoolList = []
				const res = await toGetSchoolList();
				this.status.code = res.code;
				this.status.msg = res.msg
				if (res.code == "200") {

					this.schoolList = res.data.filter((p) => {
						return p.schoolId != "-1"
					})
				}
			} catch (err) {
				this.status.code = "405",
					this.status.msg = "网络不好，请稍后重试"
			}
		},

	}
});